<template>
	<!-- 历史记账页 -->
	<view class="wrap back" style="padding-top: 20rpx;" >
		<view
		    style="margin-bottom: 30rpx;"
			class="warp-back item Acenter"
			v-for="(item, index) in billListData"
			:key="index"
			@click="urlDetailHome(item)"
		>
			<view class="flex flex-align-center Jbetween">
				<!-- <image src="../static/jizhang.png"></image> -->
				<view class="flex-1">
					<text class="title f30">{{ item.month }}月支出</text>
					<text class="c999 f24" style="margin-top: 20rpx; margin-bottom: 20rpx">{{ item.name }}</text>
					<text class="c999 f24">{{ item.createtime || '暂无时间' }}</text>
				</view>
				<text class="money f34">¥{{ item.operating  || 0}}</text>
			</view>
			
			<uni-transition :duration="1000" :mode-class="'slide-bottom'"  :show="true" >
				<view class="warp-status" style="display: flex;justify-content: space-between;margin-top: 30rpx;">
					<text v-if="item.adopt_id==1"  class="warning" style="font-weight: bold;font-size: 25rpx;">当前状态：待审批</text>
					<text  v-if="item.adopt_id==3" class="success" style="font-weight: bold;font-size: 25rpx;">当前状态：已通过</text>
					<text  v-if="item.adopt_id==4" class="warning" style="font-size: 25rpx;font-weight: bold;">当前状态 : 初审通过</text>
					<text  v-if="item.adopt_id==2" class="error" style="font-weight: bold;font-size: 25rpx;">当前状态：未通过</text>
					<u-button v-if="item.adopt_id==2" type="error" size="mini"  @click="resetSubmit(item)" style="font-weight: bold;">重新提交</u-button>
				</view>
			</uni-transition>
		</view>
		<view class="" style="margin-top: 50rpx;margin-bottom: 60rpx;">
			<u-loadmore
			  :status="status" 
			  :loading-text="loadingText" 
			  :loadmore-text="loadmoreText" 
			  :nomore-text="nomoreText" 
			    />
		</view>
	</view>
</template>

<script>
import util from '../../../utils/util.js';
export default {
	data() {
		return {
			
			 status: 'nomore',
			 loadingText: '努力加载中',
			 loadmoreText: '轻轻上拉',
			 nomoreText: '实在没有了',
			 business_specific_type:"", //法人记账指标类型  1 旅行社记账  2  景区记账  3  酒店记账  4  新业态记账  5  乡村民宿记账  6 乡村农家乐记账  7  乡村餐馆记账
		    // 记账列表数据
			billListData: [],
			//  类型人
			user_type: '',
			// 用户id
			id: '',
			type_id:'',//具体业务类型
			// 用户信息
			userInfo:"",
			// 审核状态
			isStatus:3,
			options:""
		};
	},
	touchStart(){
		console.log('上啦')
	},
	/*下拉刷新*/
	onPullDownRefresh: function() {
		this.status='loading'
		let userInfo = uni.getStorageSync('userInfo');
		console.log('yonghu xinxi ',userInfo)
		let openid = uni.getStorageSync('openid')
		if (userInfo) {
			this.userInfo = userInfo
			this.id = userInfo[0].id,
			this.user_type = userInfo.user_type
		}
		if(userInfo.user_type=="法人"){
			this.type_id=userInfo[0].business_specific_type
			this.business_specific_type=userInfo[0].business_specific_type
		
		}else if(userInfo.user_type=="自然人"){
			console.log('自然人信息',userInfo[0].flag1)
			this.type_id=userInfo[0].flag1
		
		}else{
			this.status="nomore"
		}
		if (this.options.id && this.options.user_type) {
			this.id=this.options.id,
			this.user_type=this.options.user_type
		} 
		// 获取记账列表数据
		this.getBillListData();
		setTimeout(() => {
			//关闭下拉刷新
			uni.stopPullDownRefresh()
		}, 1000)
	},
	onShow() {
		// 获取记账列表数据
		this.getBillListData();
	},
	onLoad(options) {
		this.status='loading'
		console.log('获取传递过来的用户信息',options)
		this.options=options
		let userInfo = uni.getStorageSync('userInfo');
		console.log('yonghu xinxi ',userInfo)
		let openid = uni.getStorageSync('openid')
		if (userInfo) {
			this.userInfo = userInfo
			this.id = userInfo[0].id,
			this.user_type = userInfo.user_type
		}
		if(userInfo.user_type=="法人"){
			this.type_id=userInfo[0].business_specific_type
			this.business_specific_type=userInfo[0].business_specific_type
		
		}else if(userInfo.user_type=="自然人"){
			console.log('自然人信息',userInfo[0].flag1)
			this.type_id=userInfo[0].flag1
		
		}else{
			this.status="nomore"
		}
		if (options.id && options.user_type) {
			this.id=options.id,
			this.user_type=options.user_type
		} 
	},
	
	onReachBottom() {
		this.loadStatus = 'loading';
		// 模拟数据加载
		setTimeout(() => {
			// this.addRandomData();
			this.loadStatus = 'loadmore';
		}, 1000);
	},
	methods: {
		// 重新提交
		resetSubmit:function(item){
			console.log('重新提交',item)
			if(this.user_type==="自然人"){
				uni.navigateTo({
					url:'../../componentsA/parse/index?item='+JSON.stringify(item)//自然人页面跳转
				})
			}else{
				console.log('历史记账页法人跳转记账',item)
				this.$set(item, 'clickType','new')//用来判断从哪进去的记账页
				if(this.business_specific_type==1 || this.business_specific_type==2  || this.business_specific_type==3){
					uni.navigateTo({
						url: "../../template/hotel/index?item="+JSON.stringify(item)//酒店记账跳转
					})
				}else if(this.business_specific_type==4 || this.business_specific_type==5 || this.business_specific_type==6){//景区记账
					uni.navigateTo({
						url: "../../template/parkLand/index?item="+JSON.stringify(item)
						})
				}else if(this.business_specific_type==7 || this.business_specific_type==8){
						uni.navigateTo({
							url: "../../template/travel/index?item="+JSON.stringify(item)//旅行社记账跳转
						})
				}else if(this.business_specific_type==9 || this.business_specific_type==10  || this.business_specific_type==11 || this.business_specific_type==12){
					uni.navigateTo({
						url: "../../library/debounce/index?item="+JSON.stringify(item)//新业态
					})
				}else if(this.business_specific_type==13){
					uni.navigateTo({
						url: "../../library/deepClone/index?item="+JSON.stringify(item)//乡村民宿
					})
				}else if(this.business_specific_type==14){
					uni.navigateTo({
						url: "../../template/countrySmile/countrySmile?item="+JSON.stringify(item)//乡村农家乐
					})
				}else if(this.business_specific_type==15){
					uni.navigateTo({
						url: "../../template/country/index?item="+JSON.stringify(item)//乡村参观
					})
				} 
			}
		},
	
		// 详情跳转
		urlDetailHome: function(item) {
			console.log('item',item)
			if (item.col == 2) {
				console.log('跳转法人详情')
				// 跳转法人详情页
				uni.navigateTo({
						url: '../../componentsA/homeDetail/index?item='+JSON.stringify(item)
					// url: '../../componentsA/homeDetail/index?id=' + item.id + '&col=' + item.col +
					// 	'&user_type=' + item.user_type + '&month=' + item.month+'&type_id=' + item.type_id
				})
			} else {
				console.log('跳转自然人详情',this.user_type)
				if(this.user_type==='联络人'){
					// 跳转自然人详情页
					uni.navigateTo({
						url: '../divider/index?id=' + item.id + '&col=' + item.col + '&user_type=' +
							item.user_type + '&month=' + item.month+'&type_id=' + item.type_id
					})
				}else if(this.user_type==='自然人'){
					console.log('开始跳转自然人了')
					// 跳转自然人详情页
					uni.navigateTo({
						url: '../divider/index?id=' + item.id + '&col=' + item.col + '&user_type=' +
							item.user_type + '&month=' + item.month+'&type_id=' + item.type_id
					})
				}
			}
		},
		// 获取记账列表数据
		getBillListData: function () {
			this.billListData=[]
			uni.showToast({
				title: '加载中...',
				icon: 'loading',
				duration: 1000
			});
			var that = this;
			uni.request({
				method: 'POST',
				url: 'https://jizhang.xqyu.cn/index.php/api/index/get_bill',
				dataType: 'json',
				header: {
					'content-type': 'application/x-www-form-urlencoded'
				},
				data: {
					uid: that.id,
					user_type: that.user_type,
					type_id:that.type_id
				},
				success: function (res) {
					that.status='nomore'
					console.log('获取历史账单',res.data)
					// 数据加载完成，隐藏弹窗
					uni.hideLoading();
					if (res.data.code == 1) {
						var result = res.data.data; // 时间格式化
						result.forEach((item, index) => {
							if (item.createtime !== null) {
								let time = util.timestampToTime(item.createtime);
								var creatTimeObj = result[index];
								creatTimeObj.createtime = time;
							}
						});
						that.billListData= res.data.data
						console.log('获取最终赋值的结果',that.billListData)
					}
				}
			});
		}
	}
};
</script>

<style>
/* page不能写带scope的style标签中，否则无效 */
page {
	background-color:#FFFFFF;
}
</style>

<style lang="scss" scoped>
	.success{
		color: #0F9B4D;
	}
	.warning{
		color: #FF8E03;
	}
	.error{
		color:#FC3E2C;
	}
.item {
    border-bottom: 1px #e5e5e5 solid;
    padding-bottom: 30rpx;
    margin-top: 30rpx;
    margin-left: 30rpx;
    margin-right: 30rpx;
}
.item image {
    width: 58rpx;
    height: 58rpx;
    margin-right: 20rpx;
}
text {
    display: block;
}
.money {
    font-weight: bold;
}
.title {
    font-weight: bold;
}

.more {
    margin-top: 100rpx;
}
</style>